package com.dong.juc;

import java.util.Hashtable;
import java.util.concurrent.locks.LockSupport;

/**
 * LockSupport的使用
 *
 * @author Administrator 2021/08/25 10:39
 */
public class LockSupportTest {

    public static void main(String[] args) {
        LockSupportTest lockSupportTest = new LockSupportTest();
        LockSupportThread lockSupportThread = new LockSupportThread(Thread.currentThread());

        lockSupportThread.start();
        LockSupport.park();
        System.out.println(Thread.currentThread().getName()+":I am running");
    }

    static class LockSupportThread extends Thread{

        private final Thread t;

        public LockSupportThread(Thread t) {
            this.t = t;
        }

        @Override
        public void run() {
            Thread currentThread = Thread.currentThread();
            System.out.println("currentThreadName:" + currentThread.getName());
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("我要启用unpark方法");
            LockSupport.unpark(t);
        }
    }
}
